import com.pbking.util.eventHandling.EventBroadcaster;
import com.pbking.util.AssetLoaderEvent;

/**
 * @author Jason Crist
 */
class com.pbking.util.AssetLoader extends EventBroadcaster {
	
	// VARIABLES //////////
	
	private var myLoader:MovieClipLoader;
	
	// CONSTRUCTION //////////
	
	function AssetLoader()
	{
		myLoader = new MovieClipLoader();
		myLoader.addListener(this);
	}
	
	// PUBLIC FUNCTIONS //////////
	
	public function loadAsset(url:String, destination:MovieClip):Void
	{
		myLoader.loadClip(url, destination);
	}
	
	// PRIVATE FUNCTIONS //////////
	
	private function onLoadComplete(target:MovieClip, httpStatus:Number):Void
	{
		dispatch(new AssetLoaderEvent(AssetLoaderEvent.LOAD_COMPLETE, target, target.getBytesTotal(), target.getBytesLoaded(), httpStatus));
	}
	
	private function onLoadError(target:MovieClip, errorCode:String, httpStatus:Number):Void
	{
		dispatch(new AssetLoaderEvent(AssetLoaderEvent.LOAD_ERROR, target, null, null, httpStatus, errorCode));
	}
	
	private function onLoadInit(target:MovieClip):Void
	{
		dispatch(new AssetLoaderEvent(AssetLoaderEvent.LOAD_INIT, target, target.getBytesTotal(), target.getBytesLoaded()));
	}
	
	private function onLoadStart(target:MovieClip):Void
	{
		dispatch(new AssetLoaderEvent(AssetLoaderEvent.LOAD_START, target));
	}
	
	private function onLoadProgress(target:MovieClip, bytesLoded:Number, bytesTotal:Number):Void
	{
		dispatch(new AssetLoaderEvent(AssetLoaderEvent.LOAD_PROGRESS, target, bytesLoded, bytesTotal));
	}
	
}